var createWindow = function (options, that, okHandler, cancelHandler) {
    var t = this;
    var uuid = this.CreateUUID();
    if (options.width) {
        options.width = options.width + "px";
    }
    if (options.height) {
        options.height = options.height + "px";
    }
    if(options.flag){
        layer = parent.layer;
    }
    var iframeSrc = options.htmlUrl;
    layer.open({
        type : 2,
        title : options.title,
        area : [options.width || "500px", options.height || "420px"],
        shade : 0.5,
        closeBtn:1,
        id : uuid,
        skin : "layui-layer-lan",
        resize : options.canResize || false,
        btn : [options.btn1 || '保存',options.btn2 || '取消'],
        maxmin : options.maxmin || false,
        content : iframeSrc,
        yes : function(index, layero) {
            var flag = true;
            var iframe = layero.find("iframe");
            var conWin = iframe[0].contentWindow;
            if (t.isFunction(conWin.beforeSaveAction)) {
                // 保存之前的动作 先执行 然后处理其他的事情
                flag = conWin.beforeSaveAction();
            }
            if (t.isFunction(conWin.saveAction)) {
                // 如果窗口中页面定义了验证函数，先验证
                if(flag){
                    if (!conWin.saveAction()) {
                        return;
                    }
                }
            }
            if(flag){
                if (t.isFunction(okHandler)) {
                    okHandler.call(that, conWin.returnData);
                }
                layer.close(index);
            }
        },
        btn2 : function(index) {
//					if (this.isFunction(cancelHandler)) {
//						cancelHandler.call(that);
//					}
            layer.close(index);
        },
        btnAlign : "r"
    });
    if (!options.extraData)
        options.extraData = {};
    //把layer及确定回调函数以便弹窗使用毁掉函数
    options.extraData.openLayer =$.extend(true, {}, layer);
    options.extraData.okHandler = okHandler;
    options.extraData.that = that;
    // 加载数据
    var iframe = $(".layui-layer-load");
    iframe.bind('load',function() {
        this.contentWindow.extraData = options.extraData;
        if(t.isFunction(this.contentWindow.extraFunc)){
            this.contentWindow.extraFunc();
        }
    });
};
var CreateUUID = function() {
    // On creation of a UUID object, set it's initial value
    function UUID() {
        this.id = this.createUUID();
    }

    // When asked what this Object is, lie and return it's value
    UUID.prototype.valueOf = function() {
        return this.id;
    };
    UUID.prototype.toString = function() {
        return this.id;
    };

    //
    // INSTANCE SPECIFIC METHODS
    //
    UUID.prototype.createUUID = function() {
        // Loose interpretation of the specification DCE 1.1: Remote
        // Procedure Call
        // since JavaScript doesn't allow access to internal systems, the
        // last 48 bits
        // of the node section is made up using a series of random numbers
        // (6 octets long).
        var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
        var dc = new Date();
        var t = dc.getTime() - dg.getTime();
        var tl = UUID.getIntegerBits(t, 0, 31);
        var tm = UUID.getIntegerBits(t, 32, 47);
        // version 1, security version is 2
        var thv = UUID.getIntegerBits(t, 48, 59) + '1';
        var csar = UUID.getIntegerBits(UUID.rand(4095), 0, 7);
        var csl = UUID.getIntegerBits(UUID.rand(4095), 0, 7);
        // since detection of anything about the machine/browser is far to
        // buggy,
        // include some more random numbers here
        // if NIC or an IP can be obtained reliably, that should be put in
        // here instead.
        var n = UUID.getIntegerBits(UUID.rand(8191), 0, 7)
            + UUID.getIntegerBits(UUID.rand(8191), 8, 15)
            + UUID.getIntegerBits(UUID.rand(8191), 0, 7)
            + UUID.getIntegerBits(UUID.rand(8191), 8, 15)
            // this last number is two octets long
            + UUID.getIntegerBits(UUID.rand(8191), 0, 15);
        return tl + tm + thv + csar + csl + n;
    };

    // Pull out only certain bits from a very large integer, used to get the
    // time
    // code information for the first part of a UUID. Will return zero's if
    // there
    // aren't enough bits to shift where it needs to.
    UUID.getIntegerBits = function(val, start, end) {
        var base16 = UUID.returnBase(val, 16);
        var quadArray = new Array();
        var quadString = '';
        var i = 0;
        for (i = 0; i < base16.length; i++) {
            quadArray.push(base16.substring(i, i + 1));
        }
        for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
            if (!quadArray[i] || quadArray[i] == '')
                quadString += '0';
            else
                quadString += quadArray[i];
        }
        return quadString;
    };

    // Replaced from the original function to leverage the built in methods
    // in
    // JavaScript. Thanks to Robert Kieffer for pointing this one out
    UUID.returnBase = function(number, base) {
        return (number).toString(base).toUpperCase();
    };

    // pick a random number within a range of numbers
    // int b rand(int a); where 0 <= b <= a
    UUID.rand = function(max) {
        return Math.floor(Math.random() * (max + 1));
    };

    return new UUID().id;
};
this.isFunction = function(obj) {
    return typeof(obj) == "function";
};